package ui;

import java.awt.EventQueue;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.plaf.FontUIResource;

import dao.DBOperation;
import export.ExportabilityImp;

import javax.swing.JScrollPane;
import net.miginfocom.swing.MigLayout;
import pojo.Company;
import pojo.TimeNode;
import util.ExcelFileFilter;
import util.ImageFileView;
import util.ImageFilter;
import util.ImagePreview;
import util.StringListSorter;

import javax.swing.JTextArea;
import javax.swing.JSeparator;
import javax.swing.JComboBox;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.awt.event.ActionEvent;
import java.awt.event.ItemListener;
import java.io.File;
import java.net.URL;
import java.awt.event.ItemEvent;
import javax.swing.JFileChooser;
import javax.swing.JPanel;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.image.ImageObserver;
import java.awt.image.ImageProducer;

import javax.swing.JCheckBox;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import javax.swing.JToolBar;

public class MainWindow {

	private JFrame frmV;
	private JTextField textField;
	private JTextField textField_1;
	private JTextField textField_2;
	private JTextField textField_3;
	private JTextField textField_4;
	private JTextField textField_5;
	private JTextField textField_6;
	private JTextField textField_7;
	private JTextField textField_9;
	private JTextField textField_11;
	private JTextField textField_13;
	private JTextField textField_15;
	private JTextField textField_17;
	private JTextField textField_19;
	private JTextField textField_21;
	private JTextField textField_22;
	private JTextField textField_23;
	private JTextArea textArea;
	private JTextArea textArea_1;
	private JTextArea textArea_2;
	private JTextArea textArea_3;
	private JComboBox comboBox;
	private JComboBox comboBox_1;
	private JLabel lblNewLabel_3;
	private JLabel lblNewLabel_4;
	private JLabel lblNewLabel_5;
	private JLabel lblNewLabel_6;
	private JLabel lblNewLabel_7;
	private JLabel lblNewLabel_8;
	private JLabel lblNewLabel_9;
	private JLabel label_26;

	private DBOperation dbOperation;
	private JFileChooser fco;
	private JFileChooser fcs;
	private JTextField textField_8;
	private JCheckBox checkBox;
	private JCheckBox checkBox_1;
	private JCheckBox checkBox_2;
	private JCheckBox checkBox_3;
	private JCheckBox checkBox_4;
	private JCheckBox checkBox_5;
	private JCheckBox checkBox_6;
	private JCheckBox checkBox_7;
	private JCheckBox checkBox_8;
	private JCheckBox checkBox_9;
	private ExportabilityImp exp;
	private JTextField textField_10;
	private JTextField textField_12;
	private JTextField textField_14;
	private JTextField textField_16;
	private JCheckBox checkBox_10;
	private JCheckBox checkBox_11;
	private JCheckBox checkBox_12;
	private JCheckBox checkBox_13;
	private JCheckBox checkBox_14;
	private JCheckBox checkBox_15;
	private JCheckBox checkBox_16;
	private JCheckBox checkBox_17;
	private JCheckBox checkBox_18;
	
	private StringListSorter sorter;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			@Override
			public void run() {
				try {
					MainWindow window = new MainWindow();
					window.frmV.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public MainWindow() {
		dbOperation = new DBOperation();
		 sorter = new StringListSorter();
		initGlobalFont();
		initialize();		
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		exp = new ExportabilityImp();
		frmV = new JFrame();

		//		ImageIcon icon = new ImageIcon("/images/new16.gif");
		//		frmV.setIconImage(icon.getImage());
		frmV.setTitle("胶州开发区项目信息管理系统 V1.0");
		frmV.setBounds(100, 100, 1179, 555);
		frmV.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frmV.getContentPane().setLayout(new MigLayout("", "[][grow][90px:n,grow][90px:n,grow][90px:n,grow][90px:n,grow][90px:n,grow][90px:n,grow][90px:n,grow][90px:n,grow][grow]", "[][][][][][::70px,grow][::70px,grow][][][::60px,grow][][][][][][::70px,grow]"));

		JToolBar toolBar = new JToolBar();
		toolBar.setFloatable(false);
		toolBar.setRollover(true);
		toolBar.setEnabled(false);
		frmV.getContentPane().add(toolBar, "cell 0 0 10 1");

		JButton button_7 = new JButton("新建");
		button_7.setBorderPainted(false);
		button_7.setIcon(new ImageIcon(MainWindow.class.getResource("/images/new16.gif")));
		button_7.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				emptyAll();
			}
		});
		toolBar.add(button_7);

		JButton button_8 = new JButton("打开");
		button_8.setBorderPainted(false);
		button_8.setIcon(new ImageIcon(MainWindow.class.getResource("/images/open16.gif")));
		button_8.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if (openCompany())
					openTimeNode();
			}
		});
		toolBar.add(button_8);

		JButton button_9 = new JButton("保存");
		button_9.setBorderPainted(false);
		button_9.setIcon(new ImageIcon(MainWindow.class.getResource("/images/save16.gif")));
		button_9.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if (isEmptyString(textField.getText())) {
					JOptionPane.showMessageDialog(frmV, "企业名称不能为空！");
					return;
				}
				if (saveCompany() && saveTimeNode())
					JOptionPane.showMessageDialog(frmV, "保存\""+textField.getText()+"\"成功！");
				else 
					JOptionPane.showMessageDialog(frmV, "保存\""+textField.getText()+"\"失败！");
			}
		});
		toolBar.add(button_9);

		JButton button_10 = new JButton("删除");
		button_10.setBorderPainted(false);
		button_10.setIcon(new ImageIcon(MainWindow.class.getResource("/images/delete16.gif")));
		button_10.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if (isEmptyString(textField.getText())) {
					JOptionPane.showMessageDialog(frmV, "企业名称不能为空！");
					return;
				}
				int o = JOptionPane.showConfirmDialog(frmV, "确定删除\""+textField.getText()+"\"？");
				if (o == 0)
					deleteCompany();
			}
		});
		toolBar.add(button_10);

		JButton button_11 = new JButton("导出本表");
		button_11.setBorderPainted(false);
		button_11.setIcon(new ImageIcon(MainWindow.class.getResource("/images/print16.gif")));
		button_11.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				exportCompany();
			}
		});
		toolBar.add(button_11);

		JButton button_12 = new JButton("导出统计");
		button_12.setBorderPainted(false);
		button_12.setIcon(new ImageIcon(MainWindow.class.getResource("/images/print16.gif")));
		button_12.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				exportCompanies();
			}
		});
		toolBar.add(button_12);
		
		JSeparator separator_3 = new JSeparator();
		frmV.getContentPane().add(separator_3, "cell 0 1 11 1,growx");

		JLabel lblNewLabel = new JLabel("企业名称");
		frmV.getContentPane().add(lblNewLabel, "cell 0 2,alignx trailing");

		textField = new JTextField();
		frmV.getContentPane().add(textField, "cell 1 2,growx");
		textField.setColumns(10);

		JLabel label_28 = new JLabel("建设单位");
		frmV.getContentPane().add(label_28, "cell 2 2,alignx trailing");

		textField_10 = new JTextField();
		frmV.getContentPane().add(textField_10, "cell 3 2,growx");
		textField_10.setColumns(10);

		JLabel label_7 = new JLabel("包项目负责人");
		frmV.getContentPane().add(label_7, "cell 4 2,alignx trailing");

		textField_6 = new JTextField();
		frmV.getContentPane().add(textField_6, "cell 5 2,growx");
		textField_6.setColumns(10);

		JLabel label_8 = new JLabel("企业联系人");
		frmV.getContentPane().add(label_8, "cell 6 2,alignx trailing");

		textField_7 = new JTextField();
		frmV.getContentPane().add(textField_7, "cell 7 2,growx");
		textField_7.setColumns(10);

		JLabel label_31 = new JLabel("联系人电话");
		frmV.getContentPane().add(label_31, "cell 8 2,alignx trailing");

		textField_16 = new JTextField();
		frmV.getContentPane().add(textField_16, "cell 9 2,growx");
		textField_16.setColumns(10);

		JLabel label_4 = new JLabel("占地");
		frmV.getContentPane().add(label_4, "cell 0 3,alignx trailing");

		textField_1 = new JTextField();
		frmV.getContentPane().add(textField_1, "cell 1 3,growx");
		textField_1.setColumns(10);

		JLabel lblNewLabel_2 = new JLabel("注册资本");
		frmV.getContentPane().add(lblNewLabel_2, "cell 2 3,alignx trailing");

		textField_2 = new JTextField();
		frmV.getContentPane().add(textField_2, "cell 3 3,growx");
		textField_2.setColumns(10);

		JLabel label = new JLabel("总投资");
		frmV.getContentPane().add(label, "cell 4 3,alignx trailing");

		textField_3 = new JTextField();
		frmV.getContentPane().add(textField_3, "cell 5 3,growx");
		textField_3.setColumns(10);

		JLabel label_1 = new JLabel("年产值");
		frmV.getContentPane().add(label_1, "cell 6 3,alignx trailing");

		textField_4 = new JTextField();
		frmV.getContentPane().add(textField_4, "cell 7 3,growx");
		textField_4.setColumns(10);

		JLabel label_29 = new JLabel("利润");
		frmV.getContentPane().add(label_29, "cell 8 3,alignx trailing");

		textField_12 = new JTextField();
		frmV.getContentPane().add(textField_12, "cell 9 3,growx");
		textField_12.setColumns(10);

		JLabel label_30 = new JLabel("税收");
		frmV.getContentPane().add(label_30, "cell 0 4,alignx trailing");

		textField_14 = new JTextField();
		frmV.getContentPane().add(textField_14, "cell 1 4,growx");
		textField_14.setColumns(10);

		JLabel label_2 = new JLabel("用工");
		frmV.getContentPane().add(label_2, "cell 2 4,alignx trailing");

		textField_5 = new JTextField();
		frmV.getContentPane().add(textField_5, "cell 3 4,growx");
		textField_5.setColumns(10);

		JLabel label_3 = new JLabel("简介");
		frmV.getContentPane().add(label_3, "cell 0 5,alignx trailing");

		JScrollPane scrollPane = new JScrollPane();
		frmV.getContentPane().add(scrollPane, "cell 1 5 4 1,grow");

		textArea = new JTextArea();
		textArea.setLineWrap(true);
		scrollPane.setViewportView(textArea);

		JLabel label_27 = new JLabel("项目属性");
		frmV.getContentPane().add(label_27, "cell 5 5,alignx trailing");

		JPanel panel_8 = new JPanel();
		frmV.getContentPane().add(panel_8, "cell 6 5 2 2,grow");
		panel_8.setLayout(new MigLayout("", "[][][]", "[][][][][]"));

		checkBox_1 = new JCheckBox("青岛市重点项目");
		panel_8.add(checkBox_1, "cell 0 0");

		checkBox_4 = new JCheckBox("亿元新开工项目");
		panel_8.add(checkBox_4, "cell 1 0");

		checkBox_3 = new JCheckBox("胶州市重点项目");
		panel_8.add(checkBox_3, "cell 0 1");

		checkBox_6 = new JCheckBox("服务业重点项目");
		panel_8.add(checkBox_6, "cell 1 1");

		checkBox_5 = new JCheckBox("投资过亿元项目");
		panel_8.add(checkBox_5, "cell 0 2");

		checkBox_8 = new JCheckBox("总部经济项目");
		panel_8.add(checkBox_8, "cell 1 2");

		checkBox_7 = new JCheckBox("青岛以外内资项目");
		panel_8.add(checkBox_7, "cell 0 3");

		checkBox = new JCheckBox("内资");
		panel_8.add(checkBox, "cell 1 3");

		checkBox_2 = new JCheckBox("战略新兴项目");
		panel_8.add(checkBox_2, "cell 0 4");

		checkBox_9 = new JCheckBox("外资");
		panel_8.add(checkBox_9, "cell 1 4");

		JLabel label_32 = new JLabel("企业分类");
		frmV.getContentPane().add(label_32, "cell 8 5,alignx trailing");

		JPanel panel_9 = new JPanel();
		frmV.getContentPane().add(panel_9, "cell 9 5 2 2,grow");
		panel_9.setLayout(new MigLayout("", "[grow][][]", "[][][][][]"));

		checkBox_10 = new JCheckBox("工业");
		panel_9.add(checkBox_10, "cell 0 0");

		checkBox_11 = new JCheckBox("营利性服务业");
		panel_9.add(checkBox_11, "cell 1 0");

		checkBox_12 = new JCheckBox("建筑业");
		panel_9.add(checkBox_12, "cell 0 1");

		checkBox_13 = new JCheckBox("住宿业和餐饮业");
		panel_9.add(checkBox_13, "cell 1 1");

		checkBox_14 = new JCheckBox("交通运输仓储和邮政业");
		panel_9.add(checkBox_14, "cell 0 2");

		checkBox_15 = new JCheckBox("金融业");
		panel_9.add(checkBox_15, "cell 1 2");

		checkBox_16 = new JCheckBox("批发业和零售业");
		panel_9.add(checkBox_16, "cell 0 3");

		checkBox_17 = new JCheckBox("非营利性服务业");
		panel_9.add(checkBox_17, "cell 1 3");

		checkBox_18 = new JCheckBox("房地产业");
		panel_9.add(checkBox_18, "cell 0 4");

		JLabel label_24 = new JLabel("备注");
		frmV.getContentPane().add(label_24, "cell 0 6,alignx trailing");

		JScrollPane scrollPane_3 = new JScrollPane();
		frmV.getContentPane().add(scrollPane_3, "cell 1 6 4 1,grow");

		textArea_3 = new JTextArea();
		textArea_3.setLineWrap(true);
		scrollPane_3.setViewportView(textArea_3);

		JSeparator separator = new JSeparator();
		frmV.getContentPane().add(separator, "cell 0 7 11 1,growx");

		JLabel label_6 = new JLabel("");
		frmV.getContentPane().add(label_6, "flowx,cell 1 8,alignx trailing");

		JLabel label_9 = new JLabel("注册");
		frmV.getContentPane().add(label_9, "cell 2 8,alignx center");

		JLabel label_11 = new JLabel("土地预审");
		frmV.getContentPane().add(label_11, "cell 3 8,alignx center");

		JLabel label_13 = new JLabel("备案");
		frmV.getContentPane().add(label_13, "cell 4 8,alignx center");

		JLabel label_15 = new JLabel("环评");
		frmV.getContentPane().add(label_15, "cell 5 8,alignx center");

		JLabel label_25 = new JLabel("土地出让合同");
		frmV.getContentPane().add(label_25, "cell 6 8,alignx center");

		JLabel lblNewLabel_1 = new JLabel("建设用地规划许可");
		frmV.getContentPane().add(lblNewLabel_1, "cell 7 8,alignx center");

		JLabel label_10 = new JLabel("建筑工程规划许可");
		frmV.getContentPane().add(label_10, "cell 8 8,alignx center");

		JLabel label_19 = new JLabel("施工许可");
		frmV.getContentPane().add(label_19, "cell 9 8,alignx center");

		JLabel label_5 = new JLabel("手续办理");
		frmV.getContentPane().add(label_5, "cell 0 9,alignx trailing");

		JLabel label_17 = new JLabel("手续文件");
		frmV.getContentPane().add(label_17, "cell 1 9,alignx trailing");

		JPanel panel = new JPanel();
		frmV.getContentPane().add(panel, "cell 2 9,alignx center,growy");
		panel.setLayout(new MigLayout("", "[::60px]", "[grow][]"));

		lblNewLabel_3 = new JLabel("");
		lblNewLabel_3.setMaximumSize(new Dimension(50, 17));
		lblNewLabel_3.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseEntered(MouseEvent e) {				
				lblNewLabel_3.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
			}
			@Override
			public void mouseExited(MouseEvent e) {
				lblNewLabel_3.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
			}
			@Override
			public void mouseClicked(MouseEvent e) {
				ImageViewer.showImageViewer(lblNewLabel_3.getToolTipText(), lblNewLabel_3.getToolTipText());
			}
		});		
		lblNewLabel_3.setForeground(Color.BLUE);
		panel.add(lblNewLabel_3, "cell 0 0,alignx center,growy");

		JButton btnNewButton = new JButton("添加");
		btnNewButton.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				setImg(lblNewLabel_3);
			}
		});
		panel.add(btnNewButton, "cell 0 1");

		JPanel panel_1 = new JPanel();
		frmV.getContentPane().add(panel_1, "cell 3 9,alignx center,growy");
		panel_1.setLayout(new MigLayout("", "[::60px]", "[grow][]"));

		lblNewLabel_4 = new JLabel("");
		lblNewLabel_4.setMaximumSize(new Dimension(50, 17));
		lblNewLabel_4.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseEntered(MouseEvent e) {				
				lblNewLabel_4.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
			}
			@Override
			public void mouseExited(MouseEvent e) {
				lblNewLabel_4.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
			}
			@Override
			public void mouseClicked(MouseEvent e) {
				ImageViewer.showImageViewer(lblNewLabel_4.getToolTipText(), lblNewLabel_4.getToolTipText());
			}
		});
		lblNewLabel_4.setForeground(Color.BLUE);
		panel_1.add(lblNewLabel_4, "cell 0 0,alignx center,growy");

		JButton button = new JButton("添加");
		button.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				setImg(lblNewLabel_4);
			}
		});
		panel_1.add(button, "cell 0 1");

		JPanel panel_2 = new JPanel();
		frmV.getContentPane().add(panel_2, "cell 4 9,alignx center,growy");
		panel_2.setLayout(new MigLayout("", "[::60px]", "[grow][]"));

		lblNewLabel_5 = new JLabel("");
		lblNewLabel_5.setMaximumSize(new Dimension(50, 17));
		lblNewLabel_5.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseEntered(MouseEvent e) {				
				lblNewLabel_5.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
			}
			@Override
			public void mouseExited(MouseEvent e) {
				lblNewLabel_5.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
			}
			@Override
			public void mouseClicked(MouseEvent e) {
				ImageViewer.showImageViewer(lblNewLabel_5.getToolTipText(), lblNewLabel_5.getToolTipText());
			}
		});
		lblNewLabel_5.setForeground(Color.BLUE);
		panel_2.add(lblNewLabel_5, "cell 0 0,alignx center,growy");

		JButton button_1 = new JButton("添加");
		button_1.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				setImg(lblNewLabel_5);
			}
		});
		panel_2.add(button_1, "cell 0 1");

		JPanel panel_3 = new JPanel();
		frmV.getContentPane().add(panel_3, "cell 5 9,alignx center,growy");
		panel_3.setLayout(new MigLayout("", "[::60px]", "[grow][]"));

		lblNewLabel_6 = new JLabel("");
		lblNewLabel_6.setMaximumSize(new Dimension(50, 17));
		lblNewLabel_6.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseEntered(MouseEvent e) {				
				lblNewLabel_6.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
			}
			@Override
			public void mouseExited(MouseEvent e) {
				lblNewLabel_6.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
			}
			@Override
			public void mouseClicked(MouseEvent e) {
				ImageViewer.showImageViewer(lblNewLabel_6.getToolTipText(), lblNewLabel_6.getToolTipText());
			}
		});
		lblNewLabel_6.setForeground(Color.BLUE);
		panel_3.add(lblNewLabel_6, "cell 0 0,alignx center,growy");

		JButton button_2 = new JButton("添加");
		button_2.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				setImg(lblNewLabel_6);
			}
		});
		panel_3.add(button_2, "cell 0 1");

		JPanel panel_7 = new JPanel();
		frmV.getContentPane().add(panel_7, "cell 6 9,alignx center,growy");
		panel_7.setLayout(new MigLayout("", "[::60px]", "[grow][]"));

		label_26 = new JLabel("");
		label_26.setMaximumSize(new Dimension(50, 17));
		label_26.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseEntered(MouseEvent e) {				
				label_26.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
			}
			@Override
			public void mouseExited(MouseEvent e) {
				label_26.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
			}
			@Override
			public void mouseClicked(MouseEvent e) {
				ImageViewer.showImageViewer(label_26.getToolTipText(), label_26.getToolTipText());
			}
		});
		label_26.setForeground(Color.BLUE);
		panel_7.add(label_26, "cell 0 0,alignx center,growy");

		JButton button_6 = new JButton("添加");
		button_6.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				setImg(label_26);
			}
		});
		panel_7.add(button_6, "cell 0 1");

		JPanel panel_4 = new JPanel();
		frmV.getContentPane().add(panel_4, "cell 7 9,alignx center,growy");
		panel_4.setLayout(new MigLayout("", "[::60px]", "[grow][]"));

		lblNewLabel_7 = new JLabel("");
		lblNewLabel_7.setMaximumSize(new Dimension(50, 17));
		lblNewLabel_7.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseEntered(MouseEvent e) {				
				lblNewLabel_7.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
			}
			@Override
			public void mouseExited(MouseEvent e) {
				lblNewLabel_7.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
			}
			@Override
			public void mouseClicked(MouseEvent e) {
				ImageViewer.showImageViewer(lblNewLabel_7.getToolTipText(), lblNewLabel_7.getToolTipText());
			}
		});
		lblNewLabel_7.setForeground(Color.BLUE);
		panel_4.add(lblNewLabel_7, "cell 0 0,alignx center,growy");

		JButton button_3 = new JButton("添加");
		button_3.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				setImg(lblNewLabel_7);
			}
		});
		panel_4.add(button_3, "cell 0 1");

		JPanel panel_5 = new JPanel();
		frmV.getContentPane().add(panel_5, "cell 8 9,alignx center,growy");
		panel_5.setLayout(new MigLayout("", "[::60px]", "[grow][]"));

		lblNewLabel_8 = new JLabel("");
		lblNewLabel_8.setMaximumSize(new Dimension(50, 17));
		lblNewLabel_8.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseEntered(MouseEvent e) {				
				lblNewLabel_8.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
			}
			@Override
			public void mouseExited(MouseEvent e) {
				lblNewLabel_8.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
			}
			@Override
			public void mouseClicked(MouseEvent e) {
				ImageViewer.showImageViewer(lblNewLabel_8.getToolTipText(), lblNewLabel_8.getToolTipText());
			}
		});
		lblNewLabel_8.setForeground(Color.BLUE);
		panel_5.add(lblNewLabel_8, "cell 0 0,alignx center,growy");

		JButton button_4 = new JButton("添加");
		button_4.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				setImg(lblNewLabel_8);
			}
		});
		panel_5.add(button_4, "cell 0 1");

		JPanel panel_6 = new JPanel();
		frmV.getContentPane().add(panel_6, "cell 9 9,alignx center,growy");
		panel_6.setLayout(new MigLayout("", "[::60px]", "[grow][]"));

		lblNewLabel_9 = new JLabel("");
		lblNewLabel_9.setMaximumSize(new Dimension(50, 17));
		lblNewLabel_9.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseEntered(MouseEvent e) {				
				lblNewLabel_9.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
			}
			@Override
			public void mouseExited(MouseEvent e) {
				lblNewLabel_9.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
			}
			@Override
			public void mouseClicked(MouseEvent e) {
				ImageViewer.showImageViewer(lblNewLabel_9.getToolTipText(), lblNewLabel_9.getToolTipText());
			}
		});
		lblNewLabel_9.setForeground(Color.BLUE);
		panel_6.add(lblNewLabel_9, "cell 0 0,alignx center,growy");

		JButton button_5 = new JButton("添加");
		button_5.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				setImg(lblNewLabel_9);
			}
		});
		panel_6.add(button_5, "cell 0 1");

		JLabel label_18 = new JLabel("办理时间");
		frmV.getContentPane().add(label_18, "cell 1 10,alignx trailing");

		textField_9 = new JTextField();
		frmV.getContentPane().add(textField_9, "cell 2 10,growx");
		textField_9.setColumns(10);

		textField_11 = new JTextField();
		frmV.getContentPane().add(textField_11, "cell 3 10,growx");
		textField_11.setColumns(10);

		textField_13 = new JTextField();
		frmV.getContentPane().add(textField_13, "cell 4 10,growx");
		textField_13.setColumns(10);

		textField_15 = new JTextField();
		frmV.getContentPane().add(textField_15, "cell 5 10,growx");
		textField_15.setColumns(10);

		textField_17 = new JTextField();
		frmV.getContentPane().add(textField_17, "cell 6 10,growx");
		textField_17.setColumns(10);

		textField_19 = new JTextField();
		frmV.getContentPane().add(textField_19, "cell 7 10,growx");
		textField_19.setColumns(10);

		textField_21 = new JTextField();
		frmV.getContentPane().add(textField_21, "cell 8 10,growx");
		textField_21.setColumns(10);

		textField_8 = new JTextField();
		frmV.getContentPane().add(textField_8, "cell 9 10,growx");
		textField_8.setColumns(10);

		JSeparator separator_1 = new JSeparator();
		frmV.getContentPane().add(separator_1, "cell 0 11 11 1,growx");

		JLabel label_12 = new JLabel("年度目标");
		frmV.getContentPane().add(label_12, "cell 0 12,alignx trailing");

		JLabel label_14 = new JLabel("完成投资");
		frmV.getContentPane().add(label_14, "cell 1 12,alignx trailing");

		textField_22 = new JTextField();
		frmV.getContentPane().add(textField_22, "cell 2 12,growx");
		textField_22.setColumns(10);

		JLabel label_16 = new JLabel("开工面积");
		frmV.getContentPane().add(label_16, "cell 3 12,alignx trailing");

		textField_23 = new JTextField();
		frmV.getContentPane().add(textField_23, "cell 4 12,growx");
		textField_23.setColumns(10);

		JSeparator separator_2 = new JSeparator();
		frmV.getContentPane().add(separator_2, "cell 0 13 11 1,growx");

		JLabel label_21 = new JLabel("年份");
		frmV.getContentPane().add(label_21, "cell 1 14,alignx trailing");

		JLabel label_20 = new JLabel("时间节点");
		frmV.getContentPane().add(label_20, "cell 0 15,alignx trailing,aligny center");

		JScrollPane scrollPane_1 = new JScrollPane();
		frmV.getContentPane().add(scrollPane_1, "cell 1 15 4 1,grow");

		textArea_1 = new JTextArea();
		textArea_1.addFocusListener(new FocusAdapter() {
			@Override
			public void focusLost(FocusEvent arg0) {
				saveTimeNode();
			}
		});
		textArea_1.setLineWrap(true);
		scrollPane_1.setViewportView(textArea_1);

		comboBox = new JComboBox();
		comboBox.addItemListener(new ItemListener() {
			@Override
			public void itemStateChanged(ItemEvent e) {
				openTimeNode();
			}
		});
		comboBoxAddRange(comboBox, 2015, 2035);
		frmV.getContentPane().add(comboBox, "cell 2 14,growx");

		JLabel label_22 = new JLabel("月份");
		frmV.getContentPane().add(label_22, "cell 3 14,alignx trailing");

		comboBox_1 = new JComboBox();
		comboBox_1.addItemListener(new ItemListener() {
			@Override
			public void itemStateChanged(ItemEvent e) {
				openTimeNode();
			}
		});
		comboBoxAddRange(comboBox_1, 1, 12);
		frmV.getContentPane().add(comboBox_1, "cell 4 14,growx");

		JLabel label_23 = new JLabel("当前进展");
		frmV.getContentPane().add(label_23, "cell 5 15,alignx trailing,aligny center");

		JScrollPane scrollPane_4 = new JScrollPane();
		frmV.getContentPane().add(scrollPane_4, "cell 6 15 4 1,grow");

		textArea_2 = new JTextArea();
		scrollPane_4.setViewportView(textArea_2);
		textArea_2.setLineWrap(true);
	}

	private void emptyAll() {
		textField.setText("");
		textField_1.setText("");
		textField_2.setText("");
		textField_3.setText("");
		textField_4.setText("");
		textField_5.setText("");
		textField_6.setText("");
		textField_7.setText("");
		textField_9.setText("");
		textField_10.setText("");
		textField_11.setText("");
		textField_12.setText("");
		textField_13.setText("");
		textField_14.setText("");
		textField_15.setText("");
		textField_16.setText("");
		textField_17.setText("");
		textField_19.setText("");
		textField_21.setText("");
		textField_8.setText("");
		textField_22.setText("");
		textField_23.setText("");
		textArea.setText("");
		textArea_1.setText("");
		textArea_2.setText("");
		textArea_3.setText("");
		lblNewLabel_3.setText("");
		lblNewLabel_3.setToolTipText("");
		lblNewLabel_4.setText("");
		lblNewLabel_4.setToolTipText("");
		lblNewLabel_5.setText("");
		lblNewLabel_5.setToolTipText("");
		lblNewLabel_6.setText("");
		lblNewLabel_6.setToolTipText("");
		label_26.setText("");
		label_26.setToolTipText("");
		lblNewLabel_7.setText("");
		lblNewLabel_7.setToolTipText("");
		lblNewLabel_8.setText("");
		lblNewLabel_8.setToolTipText("");
		lblNewLabel_9.setText("");
		lblNewLabel_9.setToolTipText("");
		checkBox.setSelected(false);
		checkBox_1.setSelected(false);
		checkBox_2.setSelected(false);
		checkBox_3.setSelected(false);
		checkBox_4.setSelected(false);
		checkBox_5.setSelected(false);
		checkBox_6.setSelected(false);
		checkBox_7.setSelected(false);
		checkBox_8.setSelected(false);
		checkBox_9.setSelected(false);
		checkBox_10.setSelected(false);
		checkBox_11.setSelected(false);
		checkBox_12.setSelected(false);
		checkBox_13.setSelected(false);
		checkBox_14.setSelected(false);
		checkBox_15.setSelected(false);
		checkBox_16.setSelected(false);
		checkBox_17.setSelected(false);
		checkBox_18.setSelected(false);
		comboBox.setSelectedIndex(0);
		comboBox_1.setSelectedIndex(0);
	}

	private void comboBoxAddRange(JComboBox comboBox, int start, int end) {
		for (int i = start; i <= end; i++)
			comboBox.addItem(i);
	}

	private boolean saveCompany() {
		if (isEmptyString(textField.getText())) {
			JOptionPane.showMessageDialog(frmV, "企业名称不能为空！");
			return false;
		}
		if (!formatTest())
			return false;
		Company company = buildCompany();
		if (dbOperation.hasCompany(company.getQiyemingcheng()))
			dbOperation.updateCompany(company);
		else
			dbOperation.addCompany(company);
		return true;
	}

	private boolean saveTimeNode() {		
//		if (isEmptyString(textArea_1.getText())) {
//			if (isEmptyString(textField_1.getText()))
//				return false;
//			else
//				
//		}
		if (isEmptyString(textField.getText())) {
			JOptionPane.showMessageDialog(frmV, "请先填写企业名称！");
			return false;
		}
		TimeNode timeNode = buildTimeNode();
		if (!dbOperation.hasCompany(textField.getText()))
			saveCompany();
		if (dbOperation.hasTimeNode(textField.getText(), timeNode.getYear(), timeNode.getMonth()))
			dbOperation.updateTimeNode(textField.getText(), timeNode);
		else
			dbOperation.addTimeNode(textField.getText(), timeNode);
		return true;
	}

	private Company buildCompany() {
		Company company = new Company();
		company.setQiyemingcheng(textField.getText());
		company.setJianshedanwei(textField_10.getText());
		company.setZhandi(textField_1.getText());
		company.setZhuceziben(textField_2.getText());
		company.setZongtouzi(textField_3.getText());
		company.setNianchanzhi(textField_4.getText());
		company.setLirun(textField_12.getText());
		company.setShuishou(textField_14.getText());
		company.setYonggong(textField_5.getText());
		company.setBaoxiangmufuzeren(textField_6.getText());
		company.setQiyelianxiren(textField_7.getText());
		company.setLianxirendianhua(textField_16.getText());
		company.setJianjie(textArea.getText());
		company.setBeizhu(textArea_3.getText());
		company.setZhucewenjian(lblNewLabel_3.getToolTipText());
		company.setZhuceshijian(textField_9.getText());
		company.setTudiyushenwenjian(lblNewLabel_4.getToolTipText());
		company.setTudiyushenshijian(textField_11.getText());
		company.setBeianwenjian(lblNewLabel_5.getToolTipText());	
		company.setBeianshijian(textField_13.getText());
		company.setHuanpingwenjian(lblNewLabel_6.getToolTipText());
		company.setHuanpingshijian(textField_15.getText());
		company.setTudichuranghetongwenjian(label_26.getToolTipText());
		company.setTudichuranghetongshijian(textField_17.getText());
		company.setJiansheyongdixukewenjian(lblNewLabel_7.getToolTipText());
		company.setJiansheyongdixukeshijian(textField_19.getText());
		company.setJianzhugongchengwenjian(lblNewLabel_8.getToolTipText());
		company.setJianzhugongchengshijian(textField_21.getText());
		company.setShigongxukewenjian(lblNewLabel_9.getToolTipText());
		company.setShigongxukeshijian(textField_8.getText());
		company.setWanchengtouzi(textField_22.getText());
		company.setKaigongmianji(textField_23.getText());
		company.setDangqianjinzhan(textArea_2.getText());
		company.setXiangmushuxing(new ArrayList<String>());
		if (checkBox_1.isSelected())
			company.getXiangmushuxing().add("青岛市重点项目");
		if (checkBox_2.isSelected())
			company.getXiangmushuxing().add("战略新兴项目");
		if (checkBox_3.isSelected())
			company.getXiangmushuxing().add("胶州市重点项目");
		if (checkBox_4.isSelected())
			company.getXiangmushuxing().add("亿元新开工项目");
		if (checkBox_5.isSelected())
			company.getXiangmushuxing().add("投资过亿元项目");
		if (checkBox_6.isSelected())
			company.getXiangmushuxing().add("服务业重点项目");
		if (checkBox_7.isSelected())
			company.getXiangmushuxing().add("青岛以外内资项目");
		if (checkBox_8.isSelected())
			company.getXiangmushuxing().add("总部经济项目");
		if (checkBox.isSelected())
			company.getXiangmushuxing().add("内资");
		if (checkBox_9.isSelected())
			company.getXiangmushuxing().add("外资");
		company.setQiyefenlei(new ArrayList<String>());
		if (checkBox_10.isSelected())
			company.getQiyefenlei().add("工业");
		if (checkBox_11.isSelected())
			company.getQiyefenlei().add("营利性服务业");
		if (checkBox_12.isSelected())
			company.getQiyefenlei().add("建筑业");
		if (checkBox_13.isSelected())
			company.getQiyefenlei().add("住宿业和餐饮业");
		if (checkBox_14.isSelected())
			company.getQiyefenlei().add("交通运输仓储和邮政业");
		if (checkBox_15.isSelected())
			company.getQiyefenlei().add("金融业");
		if (checkBox_16.isSelected())
			company.getQiyefenlei().add("批发业和零售业");
		if (checkBox_17.isSelected())
			company.getQiyefenlei().add("非营利性服务业");
		if (checkBox_18.isSelected())
			company.getQiyefenlei().add("房地产业");
		
		return company;
	}

	private TimeNode buildTimeNode() {
		TimeNode timeNode = new TimeNode();
		timeNode.setYear((Integer)comboBox.getSelectedItem());
		timeNode.setMonth((Integer)comboBox_1.getSelectedItem());
		timeNode.setDescription(textArea_1.getText());
		return timeNode;
	}

	private boolean openCompany() {
		List<String> names = dbOperation.findAllCompanyNames();	
//		names.sort(new PinyinComparator());
		sorter.sort(names, new PinyinComparator());
		String selectedName =  (String)JOptionPane.showInputDialog(frmV, "选择企业名称", "打开", JOptionPane.PLAIN_MESSAGE, null, names.toArray(), null);
		if (selectedName == "" || selectedName== null)
			return false;
		Company company;
		if ((company = dbOperation.findCompany(selectedName)) == null) {
			JOptionPane.showMessageDialog(frmV, "找不到该企业！数据库可能出错。");
			return false;
		}
		emptyAll();
		textField.setText(company.getQiyemingcheng());
		textField_10.setText(company.getJianshedanwei());
		textField_1.setText(company.getZhandi());
		textField_2.setText(company.getZhuceziben());
		textField_3.setText(company.getZongtouzi());
		textField_4.setText(company.getNianchanzhi());
		textField_12.setText(company.getLirun());
		textField_14.setText(company.getShuishou());
		textField_5.setText(company.getYonggong());
		textField_6.setText(company.getBaoxiangmufuzeren());
		textField_7.setText(company.getQiyelianxiren());
		textField_16.setText(company.getLianxirendianhua());
		textArea.setText(company.getJianjie());
		textArea_3.setText(company.getBeizhu());
		lblNewLabel_3.setText(underlineString(ImgFileString(company.getZhucewenjian())));
		lblNewLabel_3.setToolTipText(company.getZhucewenjian());
		textField_9.setText(company.getZhuceshijian());
		lblNewLabel_4.setText(underlineString(ImgFileString(company.getTudiyushenwenjian())));
		lblNewLabel_4.setToolTipText(company.getTudiyushenwenjian());
		textField_11.setText(company.getTudiyushenshijian());
		lblNewLabel_5.setText(underlineString(ImgFileString(company.getBeianwenjian())));
		lblNewLabel_5.setToolTipText(company.getBeianwenjian());
		textField_13.setText(company.getBeianshijian());
		lblNewLabel_6.setText(underlineString(ImgFileString(company.getHuanpingwenjian())));
		lblNewLabel_6.setToolTipText(company.getHuanpingwenjian());
		textField_15.setText(company.getHuanpingshijian());
		label_26.setText(underlineString(ImgFileString(company.getTudichuranghetongwenjian())));
		label_26.setToolTipText(company.getTudichuranghetongwenjian());
		textField_17.setText(company.getTudichuranghetongshijian());
		lblNewLabel_7.setText(underlineString(ImgFileString(company.getJiansheyongdixukewenjian())));
		lblNewLabel_7.setToolTipText(company.getJiansheyongdixukewenjian());
		textField_19.setText(company.getJiansheyongdixukeshijian());
		lblNewLabel_8.setText(underlineString(ImgFileString(company.getJianzhugongchengwenjian())));
		lblNewLabel_8.setToolTipText(company.getJianzhugongchengwenjian());
		textField_21.setText(company.getJianzhugongchengshijian());
		lblNewLabel_9.setText(underlineString(ImgFileString(company.getShigongxukewenjian())));
		lblNewLabel_9.setToolTipText(company.getShigongxukewenjian());
		textField_8.setText(company.getShigongxukeshijian());
		textField_22.setText(company.getWanchengtouzi());
		textField_23.setText(company.getKaigongmianji());
		textArea_2.setText(company.getDangqianjinzhan());
		for (String str: company.getXiangmushuxing()) {
			switch (str) {
			case "青岛市重点项目":
				checkBox_1.setSelected(true);
				break;
			case "战略新兴项目":
				checkBox_2.setSelected(true);
				break;
			case "胶州市重点项目":
				checkBox_3.setSelected(true);
				break;
			case "亿元新开工项目":
				checkBox_4.setSelected(true);
				break;
			case "投资过亿元项目":
				checkBox_5.setSelected(true);
				break;
			case "服务业重点项目":
				checkBox_6.setSelected(true);
				break;
			case "青岛以外内资项目":
				checkBox_7.setSelected(true);
				break;
			case "总部经济项目":
				checkBox_8.setSelected(true);
				break;
			case "内资":
				checkBox.setSelected(true);
				break;
			case "外资":
				checkBox_9.setSelected(true);
				break;
			}
		}
		for (String str: company.getQiyefenlei()) {
			switch (str) {
			case "工业":
				checkBox_10.setSelected(true);
				break;
			case "营利性服务业":
				checkBox_11.setSelected(true);
				break;
			case "建筑业":
				checkBox_12.setSelected(true);
				break;
			case "住宿业和餐饮业":
				checkBox_13.setSelected(true);
				break;
			case "交通运输仓储和邮政业":
				checkBox_14.setSelected(true);
				break;
			case "金融业":
				checkBox_15.setSelected(true);
				break;
			case "批发业和零售业":
				checkBox_16.setSelected(true);
				break;
			case "非营利性服务业":
				checkBox_17.setSelected(true);
				break;
			case "房地产业":
				checkBox_18.setSelected(true);
				break;
			}
		}
		TimeNode firstTimeNode = dbOperation.findFirstTimeNode(company.getQiyemingcheng());
		if (firstTimeNode != null) {
			comboBox.setSelectedItem(firstTimeNode.getYear());
			comboBox_1.setSelectedItem(firstTimeNode.getMonth());
		}
		return true;
	}

	private boolean openTimeNode() {
		TimeNode timeNode;
		if (isEmptyString(textField.getText()) || (timeNode = dbOperation.findTimeNode(textField.getText(), (Integer)comboBox.getSelectedItem(), 
				(Integer)comboBox_1.getSelectedItem())) == null) {
			textArea_1.setText("");
			return false;
		}
		textArea_1.setText(timeNode.getDescription());
		return true;
	}

	private void exportCompany() {
		Company company = buildCompany();
//		List<TimeNode> timeNodes = null;
//		if (!isEmptyString(textField.getText()))
//			timeNodes = dbOperation.findTimeNodes(textField.getText(), (Integer)comboBox.getSelectedItem());
//		else
//			timeNodes = buildTimeNode();
		TimeNode timeNode = buildTimeNode();
		File file = saveFile();
		if (file == null)
			return;		
		int option = 1;
		if (file.exists()){
			option = JOptionPane.showConfirmDialog(frmV, "文件已存在，确定覆盖？");
			if (option != 0)
				return;
		}
		String filePath = file.getAbsolutePath();
		if (!filePath.toLowerCase().endsWith(".xls"))
			filePath += ".xls";
		if (exp.exportSinglePage(filePath, company, timeNode))
			JOptionPane.showMessageDialog(frmV, "导出成功！");
		else
			JOptionPane.showMessageDialog(frmV, "导出失败！请确定该文件没有被其他程序使用。");
	}

	private void exportCompanies() {
		ExportDialog.showExportDialog();
	}

	private void deleteCompany() {
		String qiyemingcheng = textField.getText();
		if (dbOperation.deleteXiangmushuxing(qiyemingcheng)&& dbOperation.deleteQiyefenlei(qiyemingcheng) && dbOperation.deleteTimeNode(qiyemingcheng)
				&& dbOperation.deleteQiyexinxi(qiyemingcheng)) {
			JOptionPane.showMessageDialog(frmV, "删除\""+qiyemingcheng+"\"成功！");
			emptyAll();
		}
		else 
			JOptionPane.showMessageDialog(frmV, "删除\""+qiyemingcheng+"\"失败!");
	}

	private boolean formatTest() {
//		if (!isEmptyString(textField_1.getText()))
//			try {
//				Double.parseDouble(textField_1.getText());
//			} catch (NumberFormatException e) {
//				JOptionPane.showMessageDialog(frmV, "\"占地\"格式错误：请输入一个浮点数，如12.34");
//				return false;
//			}
//		if (!isEmptyString(textField_2.getText()))
//			try {
//				Double.parseDouble(textField_2.getText());
//			} catch (NumberFormatException e) {
//				JOptionPane.showMessageDialog(frmV, "\"注册资本\"格式错误：请输入一个浮点数，如12.34");
//				return false;
//			}
//		if (!isEmptyString(textField_3.getText()))
//			try {
//				Double.parseDouble(textField_3.getText());
//			} catch (NumberFormatException e) {
//				JOptionPane.showMessageDialog(frmV, "\"总投资\"格式错误：请输入一个浮点数，如12.34");
//				return false;
//			}
//		if (!isEmptyString(textField_4.getText()))
//			try {
//				Double.parseDouble(textField_4.getText());
//			} catch (NumberFormatException e) {
//				JOptionPane.showMessageDialog(frmV, "\"年产值\"格式错误：请输入一个浮点数，如12.34");
//				return false;
//			}
//		if (!isEmptyString(textField_12.getText()))
//			try {
//				Double.parseDouble(textField_12.getText());
//			} catch (NumberFormatException e) {
//				JOptionPane.showMessageDialog(frmV, "\"利润\"格式错误：请输入一个浮点数，如12.34");
//				return false;
//			}
//		if (!isEmptyString(textField_14.getText()))
//			try {
//				Double.parseDouble(textField_14.getText());
//			} catch (NumberFormatException e) {
//				JOptionPane.showMessageDialog(frmV, "\"税收\"格式错误：请输入一个浮点数，如12.34");
//				return false;
//			}
//		if (!isEmptyString(textField_5.getText()))
//			try {
//				Integer.parseInt(textField_5.getText());
//			} catch (NumberFormatException e) {
//				JOptionPane.showMessageDialog(frmV, "\"用工\"格式错误：请输入一个整数，如1234");
//				return false;
//			}
//		if (!isEmptyString(textField_22.getText()))
//			try {
//				Double.parseDouble(textField_22.getText());
//			} catch (NumberFormatException e) {
//				JOptionPane.showMessageDialog(frmV, "\"完成投资\"格式错误：请输入一个浮点数，如12.34");
//				return false;
//			}
//		if (!isEmptyString(textField_23.getText()))
//			try {
//				Double.parseDouble(textField_23.getText());
//			} catch (NumberFormatException e) {
//				JOptionPane.showMessageDialog(frmV, "\"开工面积\"格式错误：请输入一个浮点数，如12.34");
//				return false;
//			}
		return true;
	}

	private void setImg(JLabel label) {
		File file = openFile();
		if (file == null)
			return;
		label.setText(underlineString("查看"));
		label.setToolTipText(file.getAbsolutePath());
	}

	private File openFile() {
		File file = null;
		if (fco == null) {
			fco = new JFileChooser();

			//Add a custom file filter and disable the default
			//(Accept All) file filter.
			fco.addChoosableFileFilter(new ImageFilter());
			fco.setAcceptAllFileFilterUsed(false);

			//Add custom icons for file types.
			fco.setFileView(new ImageFileView());

			//Add the preview pane.
			fco.setAccessory(new ImagePreview(fco));
		}

		//Show it.
		int returnVal = fco.showOpenDialog(frmV);

		//Process the results.
		if (returnVal == JFileChooser.APPROVE_OPTION) {
			file = fco.getSelectedFile();
		}
		//Reset the file chooser for the next time it's shown.
		fco.setSelectedFile(null);
		return file;
	}

	private File saveFile() {
		File file = null;
		if (fcs == null) {
			fcs = new JFileChooser();
			//fcs.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
			//Add a custom file filter and disable the default
			//(Accept All) file filter.
			//fcs.addChoosableFileFilter(new ImageFilter());
			//fcs.setAcceptAllFileFilterUsed(false);		
			ExcelFileFilter excelFilter = new ExcelFileFilter(); //excel过滤器    
			fcs.addChoosableFileFilter(excelFilter);  
			fcs.setFileFilter(excelFilter); 
		}

		//Show it.
		int returnVal = fcs.showSaveDialog(frmV);

		//Process the results.
		if (returnVal == JFileChooser.APPROVE_OPTION) {
			file = fcs.getSelectedFile();
		}
		//Reset the file chooser for the next time it's shown.
		fcs.setSelectedFile(null);
		return file;
	}

	private boolean isEmptyString(String s) {
		Pattern p = Pattern.compile("^\\s*$");
		Matcher m = p.matcher(s);
		return m.find();
	}

	private String ImgFileString(String path) {
		if (path == null)
			return "";
		File file = new File(path);
		if (!file.exists())
			return "文件失效";
		return "查看";
	}

	private String underlineString(String s) {
		if (s == null)
			return "";
		return "<HTML><U>" + s +"</U></HTML>";
	}

	private String cancelUnderlineString(String s) {
		Pattern p = Pattern.compile("(?i)<HTML><U>(.*)</U></HTML>");
		Matcher m = p.matcher(s);
		if (m.find())
			return m.group(1);
		return s;
	}

	private static void initGlobalFont(){
		FontUIResource fontUIResource = new FontUIResource(new Font("宋体",Font.PLAIN, 12));
		for (Enumeration keys = UIManager.getDefaults().keys(); keys.hasMoreElements();) {
			Object key = keys.nextElement();
			Object value= UIManager.get(key);
			if (value instanceof FontUIResource) {
				UIManager.put(key, fontUIResource);
			}  
		}
	}
}
